package com.gscitysfy.cus.drain.modules.inspection.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gscitysfy.cloudfrmwk.assistant.constant.SecurityConstants;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.inspection.entity.DrainInspectionMnProblem;
import com.gscitysfy.cus.drain.modules.inspection.service.IDrainInspectionMnProblemService;
import com.gscitysfy.cus.drain.modules.inspection.vo.DrainInspectionMnProblemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;



/**
 * <p>
 * 维养问题管理
 * </p>
 *
 * @author Administrator
 * @since 2022-10-14 15:00:46
 */
@RestController
@RequestMapping("/inspection/drain-inspection-mn-problem")
@Tag(name = "维养问题管理")
@SecurityRequirement(name = SecurityConstants.OPEN_API_SECURITY_SCHEME_BEARER_NAME)
public class DrainInspectionMnProblemController {

    @Resource
    private IDrainInspectionMnProblemService drainInspectionMnProblemService;

    @Resource
    private HttpServletResponse httpServletResponse;


    /**
     * 新增维养问题
     *
     * @param drainInspectionMnProblem
     * @return
     */
    @PostMapping("/save-problem")
    @Operation(summary = "新增维养问题", description = "新增维养问题",
            responses = {
                    @ApiResponse(description = "新增维养问题", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainInspectionMnProblem.class)))
            })
    public Result saveProblem(@RequestBody DrainInspectionMnProblem drainInspectionMnProblem) {
        return Result.content(drainInspectionMnProblemService.saveProblem(drainInspectionMnProblem));
    }


    /**
     * 根据ID删除维养问题
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete-problem")
    @Operation(summary = "根据ID删除维养问题", description = "根据ID删除维养问题",
            responses = {
                    @ApiResponse(description = "根据ID删除维养问题", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainInspectionMnProblem.class)))
            })
    @Parameters({
            @Parameter(name = "ids", description = "ID", example = "1", required = true),
    })
    public Result deleteProblem(String ids) {
        return Result.content(drainInspectionMnProblemService.deleteProblemByIds(ids));
    }


    /**
     * 查询问题详情
     *
     * @param id
     * @return
     */
    @GetMapping("/viewById")
    @Operation(summary = "查询问题详情", description = "查询问题详情",
            responses = {
                    @ApiResponse(description = "查询问题详情", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainInspectionMnProblem.class)))
            })
    @Parameters({
            @Parameter(name = "id", description = "ID", example = "1", required = true),
    })
    public Result viewById(String id) {
        return Result.content(drainInspectionMnProblemService.viewById(id));
    }


    /**
     * 分页获取维养问题单列表
     *
     * @param drainInspectionMnProblemVo
     * @return
     */
    @PostMapping("/getProblemListByCondition")
    @Operation(summary = "分页获取维养问题单列表", description = "分页获取维养问题单列表")
    @Parameters({
            @Parameter(required = false, name = "cmProblemBasis", description = "问题依据"), @Parameter(required = false, name = "cmProblemType", description = "问题类别"),
            @Parameter(required = false, name = "cmProblemNo", description = "问题编号"), @Parameter(required = false, name = "cmProblemApprovalStatus", description = "问题审核状态，0表待审核，1表示审核通过，2表示审核不通过"),
            @Parameter(required = false, name = "cmStartProblemReportTime", description = "问题开始上报时间"), @Parameter(required = false, name = "cmEndProblemReportTime", description = "问题结束上报时间"),
            @Parameter(required = false, name = "cmProblemStatus", description = "问题状态"), @Parameter(required = false, name = "cmProblemIsCreateOrder", description = "是否创建维修单 0表示未创建，1表示创建"),
            @Parameter(required = false, name = "isPage", description = "类别是否分页，默认分页")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.PROBLEM_BASIS, targetField = "wtyj"),
            @FieldParam(dictType = DicConstant.PLAN_OBJECT_TYPE, targetField = "jhdxlx"),
            @FieldParam(dictType = DicConstant.JOB_STATUS, targetField = "wtzt")
    })
    public Result<IPage<DrainInspectionMnProblem>> getPointListByCondition(@Parameter(hidden = true) @RequestBody DrainInspectionMnProblemVo drainInspectionMnProblemVo) {
        IPage<DrainInspectionMnProblem> problemListByCondition = drainInspectionMnProblemService.getProblemListByCondition(drainInspectionMnProblemVo);
        return Result.content(problemListByCondition);
    }


    /**
     * 导出维养问题
     * @param drainInspectionMnProblemVo
     */
    @PostMapping("/exportPatrolFile")
    @Operation(summary = "导出维养问题", description = "导出维养问题")
    public void exportPatrolFile(@RequestBody DrainInspectionMnProblemVo drainInspectionMnProblemVo) {
        this.drainInspectionMnProblemService.exportPatrolFile(httpServletResponse,drainInspectionMnProblemVo);
    }


    /**
     * 复核
     *
     * @param cmKid
     * @param cmProblemApprovalStatus
     * @param cmProblemApprovalComments
     * @return
     */
    @PostMapping("/problemRepairById")
    @Operation(summary = "复核", description = "复核",
            responses = {
                    @ApiResponse(description = "复核", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainInspectionMnProblem.class)))
            })
    @Parameters({
            @Parameter(name = "cmKid", description = "主键", example = "1", required = true),
            @Parameter(name = "cmProblemApprovalStatus", description = "问题审核状态，0表待审核，1表示审核通过，2表示审核不通过", example = "1", required = true),
            @Parameter(name = "cmProblemApprovalComments", description = "复核意见", example = "通过", required = true)
    })
    public Result approveRepairById(Long cmKid, Integer cmProblemApprovalStatus, String cmProblemApprovalComments) {
        return Result.content(drainInspectionMnProblemService.updateProblemById(cmKid, cmProblemApprovalStatus, cmProblemApprovalComments));
    }


    /**
     * APP新增问题
     * @param drainInspectionMnProblem
     * @return
     */
    @PostMapping("/app-save-problem")
    @Operation(summary = "APP新增问题", description = "APP新增问题",
            responses = {
                    @ApiResponse(description = "APP新增问题", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainInspectionMnProblem.class)))
            })
    public Result appSaveProblem(@RequestBody DrainInspectionMnProblem drainInspectionMnProblem) {
        return Result.content(drainInspectionMnProblemService.appSaveProblem(drainInspectionMnProblem));
    }


    /**
     * APP新增问题是否处置完毕
     *
     * @param drainInspectionMnProblem
     * @return
     */
    @PostMapping("/app-update-problem")
    @Operation(summary = "APP新增问题是否处置完毕", description = "APP新增问题是否处置完毕",
            responses = {
                    @ApiResponse(description = "APP新增问题是否处置完毕", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainInspectionMnProblem.class)))
            })
    public Result appUpdateProblem(@RequestBody DrainInspectionMnProblem drainInspectionMnProblem) {
        return Result.content(drainInspectionMnProblemService.appUpdateProblem(drainInspectionMnProblem));
    }


    /**
     * APP端首页数量统计
     * @return
     */
    @GetMapping("/app-count-stat")
    @Operation(summary = "APP首页底部数量统计", description = "APP首页底部数量统计")
    @Parameters({
            @Parameter(name = "type", description = "统计类型，按日：day， 按月：month",  required = true)
    })
    public Result appCountProblem(@RequestParam("type") String type) {
        return Result.content(drainInspectionMnProblemService.appCountProblem(type));
    }
}
